package com.neegix.system.user.infrastructure.repository.impl;

import com.neegix.application.query.NebulaSQL;
import com.neegix.base.PageVO;
import com.neegix.system.user.application.assembler.UserAssembler;
import com.neegix.system.user.application.repository.UserQueryRepository;
import com.neegix.system.user.infrastructure.repository.dataobject.UserDO;
import com.neegix.system.user.infrastructure.repository.mapper.UserMapper;
import com.neegix.system.user.infrastructure.repository.mapper.customized.UserCustomizedMapper;
import com.neegix.system.user.interfaces.vo.UserForExportVO;
import com.neegix.system.user.interfaces.vo.UserForListVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
  * This file is auto-generated by nebula-framework-generator.
  * The auto-generation plugin was developed using IntelliJ IDEA Community Edition.
  * Thanks to JetBrains for their outstanding contributions to the developer community.
  * <p>
  * The code generated by this tool is owned by the user of the tool.
  * The tool itself is copyrighted by <a href="https://www.neegix.com">https://www.neegix.com</a>.
  *
  * @author <a href="https://www.neegix.com">https://www.neegix.com</a>
  * @version 1.0.0
  * @since 2024-12-03 11:47:28
  */

@Repository
public class UserQueryRepositoryImpl implements UserQueryRepository {

    @Autowired
    private UserMapper userMapper;

    @Autowired
    private UserCustomizedMapper userCustomizedMapper;

    @Override
    public PageVO<UserForListVO> findPage(Integer currentPage, Integer pageSize, NebulaSQL nebulaSQL) {
        nebulaSQL.setPager(currentPage, pageSize);
        List<UserDO> result = userMapper.selectList(nebulaSQL);
        Long total = userMapper.selectCount(nebulaSQL);
        PageVO<UserForListVO> page = new PageVO<>(currentPage, pageSize);
        page.setTotal(total);
        page.setResult(UserAssembler.INSTANCE.covertVO(result));
        return page;
    }

    @Override
    public List<UserForExportVO> findUsers() {
        return userCustomizedMapper.selectUsers();
    }
}
